<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>还款申请流程附加页</title>
<jsp:include page="../../import.jsp" flush="true" />
<%--<jsp:include page="assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->--%>
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div  >
			<form id="repay_form">
                <div class="sqPanel">
                    <div class="sqPanel_head inL">
                        <span>还 款 申 请</span>
                    </div>
                </div>
                <!-- 列表显示块 -->
                <div id="ligergrid1" class="sq-grid"></div>
                <div class="fieldBox col_50" align="right">
                    <div class="label requiredSymbol"  >剩余未还金额(元):
                        <span class="requiredSymbol" id="arAmts" name="arAmts"> </span>
                    </div>
                </div>


                <div class="sqPanel" style="margin-top: 15px">
                    <div class="sqPanel_head inL">
                        <div class="btnsBox inLC">
                            <span id="addBtn" class="sq-button sq-button-round">添加还款</span>
                            <span id="delBtn" class="sq-button sq-button-round">删除还款</span>
                        </div>
                        <span>还 款 信 息</span>
                    </div>
                 </div>   
                <!-- 列表显示块 -->
                <div id="ligergrid_repay" class="sq-grid"></div>
		             <div class="sqPanel">
		                <div class="sqPanel_head inL">
		                    <span> 退款 信息 </span>
		                </div>
		            </div>
				<div id="tuiDiv">
		            <div class="fieldset1 clearFix">
		             <div class="fieldBox">
		                   <div class="label">处置接收人类型<span class="requiredSymbol">*</span>
							</div>
							<div class="field">
								<select name="handleWayCd" id="handleWayCd"
									ligerui="width: 160" >
									<option value="0" selected>请选择</option>
									<option value="1">退款</option>
									<option value="2">转其他资产还款</option>
								</select>
							</div>
				       </div>
		            </div>    
            </div>
		            <div id="ligergrid_tui" class="sq-grid"></div>
            <div class="fieldset1 tabel_col clearFix" style="margin-top: 15px" >
                <div class="fieldBox col_100" id="fileDiv">
                    <div class="label">附件上传</div>
                    <div class="field">
                        <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
                            <jsp:param name="filePath" value="/repay"/>
                        </jsp:include>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">备注</div>
                    <div class="field">
                        <textarea name="repayRem" id="repayRem" rows="6" class="ui-textarea l-textarea" style="width:80%" value="" validate="{maxlength:200}"></textarea>
                    </div>
                </div>
            </div>
            <%--附件--%>
            <div class="sqPanel">
                <div class="sqPanel_head inL">
                    <span>附 件</span>
                    <span class="btns"><span class="sq-button sq-button-round" onclick="downloadFileByUrl();">打包下载</span></span>
                </div>
                <div class="sqPanel_body">
                    <div id="fileInfoCfgGrid" class="sq-grid"></div>
                </div>
            </div>
                <!-- 退款 实际放款时间-->
                <div class="sqPanel">
                <div class="sqPanel_body">
               		 <div id="ligergrid_isTuiPay" class="sq-grid"></div>
                </div>
                </div>
			</form>
             <div class="formBtns"  style="text-align: center;" id="saveDiv">
                    <span   onclick="save()" class="sq-button sq-button-round">保存</span>
             </div>
		 </div>
	</div>

	<script type="text/javascript">
	var repayId = '${repayId}';//还款申请id
	var usedAmount = '${usedAmount}';//退款应付金额
	var isTuiHiden = '${isTuiHiden}';//退款是否隐藏 1 显示
	var isTuiPay = '${isTuiPay}';//退款 财务核查节点 实际付款维护 1 维护
	var isBoundFunds = '${isBoundFunds}';//是否绑卡编辑  1
	var handleWayCd = '${handleWayCd}';//还款方式cd
	var fileInfoCfgGrid = null;
	var grid = null;
	var tuiPayGrid = null;
    //我司收款账号
    var myComAccListJSON = [];

    //是否可以编辑  驳回呈报人节点可修改 还款信息
    if ('${editFlag}' == 2) {
        var editFlag = true;
    }
    // var editFlag = true;

    $(function () {
		//初始化还款列表
        initGrid();
        initGrid_repay()//初始还款信息

		//初始化文件
		//initFile(repayId);
		
		//退款信息
		//initBackInfo();
		if(isTuiHiden==1){
			 if(handleWayCd){
				  $("#handleWayCd").val(handleWayCd);
				 
			 }
		     initTuiGrid();//初始退款列表
		}else{
			$("#tuiDiv").remove();
		     initTuiGrid();//初始退款列表
		}
		initFileGrid();//附件
		initGridTuiPay()//初始退款财务核查节点
        $('#repay_form').ligerForm({
            validate : true
        });
        //添加还款 和删除还款
        $("#addBtn").click(function (event) {
            rmtGrid.addRow({
                repayAmt: '',
                repayAccNm: '',
                repayAccNo: '',
                repayTm: '',
                acceptBkNm:'',
                acceptAccNo:''
            });
        });
        $("#delBtn").click(function (event) {
            var selectedRows = rmtGrid.getSelectedRows();
            if(selectedRows.length == 0){
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
                return;
            }
            rmtGrid.deleteSelectedRow();
        });
         if (!editFlag) {
             $("#addBtn").remove();
             $("#delBtn").remove();
             $("#fileDiv").remove();
         }

        var saveFlag = false;
         if (editFlag || isTuiHiden=='1' || isTuiPay=='1') {
             saveFlag = true;
         }
         if (!saveFlag) {
             $("#saveDiv").hide();
         }
	});

	//初始化 退款 列表
	function initTuiGrid(){
		
    	grid =$("#ligergrid_tui").ligerGrid({
			url:'<%=path%>/finpayschfee/finance/selectRepayBankList.do?repayId='+repayId ,
			method:'get',
			// parms:getSearchParams(),
			columns:[
                { display: '收款账户', name: 'rcptUnt', width: 100, enabledSort:true,},
                { display: '收款账号', name: 'accNo', width: 250, enabledSort:true},
				{ display: '开户行', name: 'payeeBkNm', width: 100, enabledSort:true,},
				{ display: '开户行行号', name: 'payeeBkNo', width: 120, enabledSort:true,},
				{ display: '应付金额(元)', name: 'accNo', width: 120, enabledSort:true,render:function () {
					return usedAmount/100;
				}},
				getBankClomn()
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:110,
			heightDiff:-2,
			usePager:false,
			// checkbox:true,//列表是否有选择框
			rownumbers:true//列表是否有行号
		});
    	//grid = liger.get("ligergrid_tui");
    	//grid.setHeight(110);
	}
	function getBankClomn(){
		 var data = '';
        		if(isTuiHiden==1){
       			 data = {
       			            display:'<a onClick="chooseBank(1)">选择银行账户列表</a>&nbsp;&nbsp; <a onClick="chooseBank(2)">新增银行账户 </a>',
       			            name: 'backQtySum',
       			            width: 300,
       			            align:'center',
       			            enabledSort:true,
       			            render:function (rowdata, rowindex, value){
       		        			return ' <a class="sq-button-hasicon" alt="删除" href="javascript:removeBank('+rowdata.id+' )"><i class="sqBtnIco_4"></i>删除</a>';
       			            }
       			        };
        		}else{
       			 data = {
       			            display:' 操作',
       			            name: 'backQtySum',
       			            width: 300,
       			            align:'center',
       			            enabledSort:true,
       			            render:function (rowdata, rowindex, value){
       		        			return '  ';
       			            }
       			        };
        		}
		  return data;
	}
	//初始化 退款金额 列表
	function initGridTuiPay(){
		var flag = false;
		if(isTuiPay==1){
			flag=true;
		}
    	tuiPayGrid =$("#ligergrid_isTuiPay").ligerGrid({
			url:'<%=path%>/finpayschfee/finance/selectTuiPay.do?repayId='+repayId ,
			method:'get',
			// parms:getSearchParams(),
			columns:[
                { display: '实际付款时间', name: 'actPayTm', width: 120, enabledSort:true, render:renderDate,
                	editor: {type: 'date'},
                    validate: function (value) {
                        if (StringUtils.isEmpty(value)) return "请填写实际付款时间！";
                    }},
				{ display: '实际付款时间金额(元)', name: 'actPayAmt', width: 150, enabledSort:true,
                	render:function (rowdata, rowindex, value ) {
					return rowdata.actPayAmt ;
					},
	                editor: {type: 'number',precision:2,
	                    toFix:true,
	                    onToFix:function(){
	                        top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2位小数！"});
	                    }
	                },
	                validate: function (value) {
	                    if (StringUtils.isEmpty(value)) return "请填实际付款金额！";
	                }
				},
			],
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:300,
			height:120,
			heightDiff:-2,
			usePager:false,
			enabledEdit: flag,//列表是否可编辑
			isScroll:false,//是否有滚动条
			// checkbox:true,//列表是否有选择框
			rownumbers:false//列表是否有行号
		});
    	tuiPayGrid = liger.get("ligergrid_isTuiPay");
    	 tuiPayGrid.setHeight(120);
         tuiPayGrid.options.isSingleCheck = true;//列表是否为单选

	}

    //初始化列表
    function initGrid(){
        var repayId = '${repayId}';
        $("#ligergrid1").ligerGrid({
            // data: data,
            method:'get',
            url:'<%=path%>/finance/finRepayApplyInfo/selectPayInfo.do?repayId='+repayId,
            columns:[
                { display: '借款人/工号', name: 'cstMgrNmAndCstMgrCd', width: 120, enabledSort:true,},
                { display: '付款单号', name: 'channelNm', width: 150, enabledSort:true,
                    render: function (rowdata, rowindex, value, column) {
                        var h ="";
                        if( rowdata.pNo != null){
                            h+='<a class="sq-button-hasicon" href="javascript:commShowFlow(';
                            h+="'"+rowdata.pInstId+"'";
                            h+=",'"+rowdata.audStsCd+"'";
                            h+=",'"+rowdata.dataId+"'";
                            h+=",'"+rowdata.formUrl+"'";
                            h+=")\"><i class='sqBtnIco_32'></i>"+rowdata.pNo+"</a>";
                        }
                        return h;
                    }
                },
                { display: '费用项', name: 'loanTypCdStr', width: 100, enabledSort:true,},
                { display: '实际借款金额(元)', name: 'payAmt', width: 100, enabledSort:true,
                    render:function (rowdata, rowindex, value, column){
                        return value/100;
                    }
                },
                { display: '承租人', name: 'cstNm', width: 100, enabledSort:true},
                { display: '支付表号', name: 'paySchNo', width: 150, enabledSort:true},
                { display: '使用金额(元)(<span class="c_red">*</span>)', name: 'repayAmt', width: 100, enabledSort:true,
                    editor: {type: 'number',precision:2,
                        toFix:true,
                        onToFix:function(){
                            top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2位小数！"});
                        }
                    },
                    validate: function (value) {
                        if (StringUtils.isEmpty(value)) return "请填写使用金额！";
                    },
                },
                getGridOperColumnContent(),//还款历史
                getGridOperColumn()//绑定资金
            ],
            onAfterShowData :function (e){
                var rows = e.rows;
                var i = 0;
                for ( var index in rows) {
                    i += rows[index].arAmt;
                }
                $("#arAmts").text(i);
                if (e.rows[0].repayRem) {
                    $("#repayRem").text(e.rows[0].repayRem);//备注
                }
            },
            //rowHeight:50, //行高调高
            usePager: false,//是否有分页便签
            root:'rows',
            record:'total',
            hideLoadButton:false,
            width:'100%',
            height:'100%',
            heightDiff:-2,
            isScroll:false,//是否有滚动条
            checkbox:false,//列表是否有选择框
            enabledEdit:editFlag,//是否能编辑
            rownumbers:true//列表是否有行号
        });
        repayGrid = liger.get("ligergrid1");
        //grid.setHeight(100);
        repayGrid.options.isSingleCheck = true;//列表是否为单选
    }
    //操作列
    function getGridOperColumnContent(){
        var data = {
            display:'还款历史',
            isSort:false,
            width:120,
            align:'center',
            render:function (rowdata, rowindex, value){
                var h="";
                h+='<a class="sq-button-hasicon" alt="还款历史" href="javascript:getrepayHisRow(';
                h+="'"+rowdata.paySchDtlId+"'";
                h+=",'"+rowdata.repayDtlId+"'";
                h+=")\"><i class=\"sqBtnIco_4\"></i>"+"还款历史"+"</a>";

                return h;
            }
        };
        return data;
    }

    //操作列
    function getGridOperColumn(){
        var data = {
            display:'绑定资金',
            isSort:false,
            width:250,
            align:'center',
            render:function (rowdata, rowindex, value){
            	
                var h="";
            	if( rowdata ){
            		if(rowdata.fundCodes){//存在,显示详情,解绑按钮
            			var fundList =rowdata.fundCodes;
            			var repayDtlId = rowdata.repayDtlId;
            			 for ( var index in fundList) {
	            			h+='<a class="sq-button-hasicon" alt="展示资金" href="javascript:showFund(';
	 		                h+="'"+fundList[index].fundId+"'";
	 		                h+=")\"><i class=\"sqBtnIco_4\"></i>"+fundList[index].fundNm+"</a>";
	 		                if(isBoundFunds==1){ //绑卡才能编辑
	 		                	h+="<a class='sq-button-hasicon' onClick= 'removeFund("+fundList[index].fundId+","+repayDtlId+")'>解绑</a></br>";
	 		                }
						}
            		}else{
            			//cstId,cstNm,repayDtlId
            			if(isBoundFunds==1){
            				h+='<a class="sq-button-hasicon" alt="绑定资金" href="javascript:toCapListPage(';
    		                h+="'"+rowdata.cstId+"'";
    		                h+=",'"+rowdata.cstNm+"'";
    		                h+=",'"+rowdata.repayDtlId+"'";
    		                h+=")\"><i class=\"sqBtnIco_4\"></i>"+"绑定资金"+"</a>";
            			}
		                
            		}
            	}
                return h;
            }
        };
        return data;
    }

    //显示流程：流程实例ID,状态,业务主键(借款)
    function commShowFlow(_pInstId, _audStsCd, _businessKey,_formUrl){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_ass_trail_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

    function initGrid_repay(){
        //我司收款银行
        var myComBankListJSON = [];
        <c:if test="${not empty myComBankListJSON}"> myComBankListJSON = ${myComBankListJSON}; </c:if>
        // //我司收款账号
        // var myComAccListJSON = [];
        <%--<c:if test="${not empty myComAccListJSON}"> yesOrNoCdListJSON = ${myComAccListJSON}; </c:if>--%>
        rmtGrid = $("#ligergrid_repay").ligerGrid({
            url: '<%=path%>/finance/finRmtRec/selectRmtRecHis.do?repayId='+repayId,
            method: 'get',
            columns: [
                {display: '还款金额(元)(<span class="c_red">*</span>)', name: 'repayAmt', minWidth: 80, type: 'text',
                    editor: {type: 'number',precision:2,
                        toFix:true,
                        onToFix:function(){
                            top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2位小数！"});
                        }
                    },
                    validate: function (value) {
                        if (StringUtils.isEmpty(value)) return "请填写还款金额！";
                    },
                },
                {display: '还款账户(<span class="c_red">*</span>)', name: 'repayAccNm', minWidth: 80, type: 'text',
                    editor: {type: 'text'},
                    validate: function (value) {
                        if (StringUtils.isEmpty(value)) return "请填写还款账户！";
                    }
                },
                {display: '还款账号(<span class="c_red">*</span>)', name: 'repayAccNo', minWidth: 80, type: 'text',
                    editor: {type: 'text'},
                    validate: function (value) {
                        if (StringUtils.isEmpty(value)) return "请填写还款账号！";
                    }
                },
                {
                    display: '交易时间(<span class="c_red">*</span>)', name: 'repayTm',
                    editor: {type: 'date'},
                    validate: function (value) {
                        if (StringUtils.isEmpty(value)) return "请填写还款账号！";
                    },
                    render: renderDate
                },
                {display: '我司收款银行', name: 'acceptBkCd', minWidth: 100,
                    editor: {
                        type: 'select',
                        data: myComBankListJSON,
                        valueField: 'key',
                        textField: 'value'
                    },
                    valueField: 'acceptBkCd',
                    textField: 'acceptBkNm',
                    render: function (item) {
                        return item.acceptBkNm;
                    }
                },
                {display: '我司收款账号', name: 'acceptBranchNm', minWidth: 100,
                    editor: {
                        type: 'select',
                        data: myComAccListJSON,
                        valueField: 'key',
                        textField: 'value'
                    },
                    valueField: 'acceptBranchNm',
                    textField: 'acceptAccNo',
                    render: function (item) {
                        return item.acceptAccNo;
                    }
                },

            ],
            //编辑之前
            onBeforeEdit: function (e) {
                //处理我司银行账户
                if (e.column.columnname == "acceptBranchNm") {
                    getMyComAccListJSON(e.record.acceptBkNm);
                    e.column.editor.data=myComAccListJSON;
                }
                if (e.column.columnname == "acceptBkCd") {
                    beforeMyComBkCd = e.value;
                }
            },
            onBeforeSubmitEdit: function (e) {
                if (e.column.columnname == "acceptBkCd") {
                    afterMyComBkCd = e.value;
                }
                if (e.selected && e.column.columnname == "acceptBkCd" && beforeMyComBkCd!=afterMyComBkCd) {
                    e.record.acceptAccNo = null;
                    e.record.acceptBranchNm = null;
                }
                beforeMyComBkCd = '';
                afterMyComBkCd = '';
            },
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 300,
            heightDiff: -2,
            enabledEdit: editFlag,
            isScroll: false,
            checkbox: editFlag,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
    }

    //根据我司银行 获取对应的账号
    function getMyComAccListJSON(acceptBkNm){
        if(!acceptBkNm){
            top.$.ligerDialog.SQalert({content: "请先选择我司收款银行", SQ_type: "warning"});
            return;
        }
        $.ajax({
            type: 'post',
            dataType:'json',
            async: false,
            data:{
                acceptBkCd:acceptBkNm
            },
            url: '<%=path%>/finance/finRepayApplyInfo/getMyComAccListJSON.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({
                    content: LogUtils.LOG_CMM_DATA_LOADING,
                    SQ_type: "waitting"
                });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    myComAccListJSON=msg.data;
                }
            }
        });
    }

    //保存（修改）还款信息等
    function saveInfo() {
        var repay_form = liger.get("repay_form");
        var isValid = SQ.validGrid('ligergrid1');
        var repayIsValid = SQ.validGrid('ligergrid_repay');

        if (isValid == false) {
            $.ligerDialog.SQalert({content: "请维护使用金额！" , SQ_type: "warning" });
            return false;
        }
        if (repayIsValid == false) {
            $.ligerDialog.SQalert({content: "请维护还款信息！" , SQ_type: "warning" });
            return false;
        }
        var data = repay_form.getData();

        data["repayInfo"] = JSON.stringify(repayGrid.getData());//还款明细
        data["rmtInfo"] = JSON.stringify(rmtGrid.getData());//打款记录
        if (rmtGrid.getData().length < 1) {
            $.ligerDialog.SQalert({content: "请维护还款信息！" , SQ_type: "warning" });
            return false;
        }
        data["repayId"] = repayId;

        var fileParams = getUploadResultParams();//获取附件上传的信息
        data["fileParams"] = JSON.stringify(fileParams);
        var wait_dialog = null;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: '<%=path%>/finance/finRepayApplyInfo/modify.do',
            beforeSend: function(){
                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
    }

	//初始附件列表
	function initFileGrid() {
        fileInfoCfgGrid = $("#fileInfoCfgGrid").ligerGrid({
            url: '<%=path%>/system/sysulfilesrec/initList.do?cstMgrOrgCd=${cstMgrOrgCd}&cstId=${cstId}',
            method: 'get',
            parms:{
                pkId:repayId,
                tabNm:'FIN_REPAY_APPLY_INFO',
            },
            columns: [
                {display: '上传文件名称', name: 'fileNm', minWidth: 100, enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            var h;
                            h='<a href="javascript:uploadFileByUrl(';
                            h+="'"+rowdata.filePath+"'";
                            h+=",'"+rowdata.fileNm+"'";
                            h+=')">'+rowdata.fileNm+'</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm', minWidth: 100, enabledSort: false,render:renderDate},
                {display: '上传人', name: 'crtUsrRlNm', width: 100, enabledSort: false},
                {display: '操作', name: '', minWidth: 100, enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='';
                        h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.id + ');"><i class="sqBtnIco_7"></i>删除</a>';
                        return h;
                    }
                },
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers:true,  //显示序号
            checkbox: false,
            allowUnSelectRow:true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
        });
    }

    //展示图片
    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            //SQ.imgPreview(_url);
            //SQ.imgPreview(_url, true);
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }

	//打包下载附件
    function downloadFileByUrl() {
        var data = fileInfoCfgGrid.getData();
//        var files = [];
        var ids = [];
        for (var i = 0; i < data.length; i++) {
            var map = {};
//		    map.name = data[i].fileNm;
//		    map.path = data[i].filePath.substring(data[i].filePath.indexOf("attachments"));
//		    files.push(map);
            ids.push(data[i].id);
        }
        var actoinURL = '<%=path%>/system/sysulfilesrec/zipDownloadById.do';
        var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);//下载文件的请求路径
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','ids');
        input.attr('value',JSON.stringify(ids));
        form.append(input);
        form.submit();
    }

    //删除文件
    function delFile(event,_fileId){
        top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
            if(!flag){
                return;
            }else{
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fileId':_fileId},
                    url: '<%=path%>/project/prjFileInfo/removeFile.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            liger.get(fileInfoCfgGrid).reload();
                        }else{
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            }
        });
    }
	
	//流程跟踪
	function showFlowForCarBiz(){
		
	}
	
	function showFlowForCarBiz(_pInstId, _audStsCd, _businessKey,_formUrl){
    	if(StringUtils.isEmpty(_pInstId)){
    		UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
    		return;
    	}
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
    	Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
	
	
	function chooseBank(_value){
		var handleWayCd = $("#handleWayCd").val();
		if(handleWayCd==1){//选择退款
			if(_value==1){//选择卡列表
				toBankList()
			}else if(_value==2){//新增卡
				toAddPage()
			}
		 }else{
			 top.$.ligerDialog.SQalert({content: "处理方式只有是退款才能选择银行卡",SQ_type: "error"});

		 } 
	}
	 function toAddPage2(){
	        parent.Add_navTab('tab_apply_bankAcc_Add','新增账号','<%=path%>/capital/finance/loan/apply/bankAcc/toAddPage.do',callback);
	        <%--parent.parent.mainApp.f_addTab('tab_apply_bankAcc_Add','新增账号','<%=path%>/capital/finance/loan/apply/bankAcc/toAddPage.do');--%>
	    }
	 function toAddPage( ){
			 var onCancel = function (item, Dialog) {
	            Dialog.hide();
	        };
	        $.ligerDialog.SQopen({
	            width: 900,
	            height:400,
	            title : '新增帐号',
	           // data:{repayDtlId:repayDtlId,cstId:cstId,bizTypCd:1,type:1},
	            url:'<%=path%>/finpayschfee/finance/toAddBankPage.do' ,
	            buttons: [ 
		                {
		                    text: "关闭", onclick: onCancel, type: 'cancel'
		                }
		        ]
	        });
	    }
	 function toCapListPage(cstId,cstNm,repayDtlId ){
		 //type=1&bizTypCd=1&relationPayId=180910104012319&cstId=180815030001355&cstNm=刘宜祯
			 //var cstId="180815030001355";
			 //var cstNm="刘宜祯";
			// var repayDtlId ="1";//还款明细id
			 var parm="type=1&bizTypCd=1&repayDtlId="+repayDtlId+"&cstId="+cstId+"&cstNm="+cstNm;
			 var onCancel = function (item, Dialog) {
	            Dialog.hide();
	        };
	        $.ligerDialog.SQopen({
	            width: 900,
	            height:400,
	            title : '资金列表',
	            data:{repayDtlId:repayDtlId,cstId:cstId,bizTypCd:1,type:1},
	            url:'<%=path%>/finpayschfee/finance/toChooseFund.do?'+parm ,
	            buttons: [ 
		                {
		                    text: "关闭", onclick: onCancel, type: 'cancel'
		                }
		        ]
	        });
	    }
	 function callback(){
		 initTuiGrid();
	 }
	//银行卡list
	function  toBankList(){
		var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '账户列表',
            url:'<%=path%>/finance/finRepayApplyInfo/toBankListPage.do?repayId='+repayId ,
            buttons: [ 
	                {
	                    text: "关闭", onclick: onCancel, type: 'cancel'
	                }
	        ]
        });
	}
	//删除绑卡
	function removeBank(_id ){
		if(!_id){
			return;
		}//ID为空不执行
		$.ajax({
            type: 'get',
            dataType:'json',
            data:{refundId:_id ,repayId:repayId},
            url: '<%=path%>/finpayschfee/finance/removeBankById.do',
            success:function(msg){
                if(msg.code == 1){
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                    grid.reload();
                }else{
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                }
            }
        });
	}
	 //查询资金信息
    function showFund(_id) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 800,
            //height: 300,
            autoFixHeight: true,
            title : '资金信息',
            url: "<%=path%>/capital/capFund/toFundDtlPage.do?id="+_id,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }
	 //解除绑定资金信息
    function removeFund(_id,repayDtlId) {
     
		 if(!_id){
			 return;
		 }
		 var _ids = [];
	     _ids.push(_id);
	       
    	$.ajax({
            type: 'post',
            dataType: 'json',
            data: {ids: JSON.stringify(_ids) ,repayDtlId:repayDtlId},
            url: '<%=path%>/finpayschfee/finance/confirmFund.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({
                    content: LogUtils.LOG_CMM_DATA_LOADING,
                    SQ_type: "waitting"
                });
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.code == 1) {
                    top.$.ligerDialog.SQalert({content: "资金解除关联成功", SQ_type: "success"});
                    parent.location.reload();
                    frameElement.dialog.close();
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_showButtons : true,SQ_type: "error"});
                }
            }
        });
    }
	 //保存按钮
    function save( ) {
        if(isTuiHiden=='1'){//退款显示, 选择退款方式节点
        	
        	var handleWayCd = $("#handleWayCd").val();
        	if (!handleWayCd || handleWayCd == 0) {
                $.ligerDialog.SQalert({content: "请选择来款处理方式！" , SQ_type: "warning" });
                return false;
            }
        	
        	$.ajax({
                type: 'post',
                dataType: 'json',
                data: { repayId:repayId,handleWayCd:handleWayCd,usedAmount:usedAmount/100},
                url: '<%=path%>/finpayschfee/finance/addhandleWayCd.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({
                        content: LogUtils.LOG_CMM_DATA_LOADING,
                        SQ_type: "waitting"
                    });
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.code == 1) {
                        top.$.ligerDialog.SQalert({content: "选择来款处理方式成功", SQ_type: "success"});
                        parent.location.reload();
                        frameElement.dialog.close();
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_showButtons : true,SQ_type: "error"});
                    }
                }
            });
        }else if(isTuiPay=='1'){
        	var aa =tuiPayGrid.getData();
         
        	if(aa){
        		$.ajax({
                    type: 'get',
                    dataType: 'json',
                    data: { refundAccId:aa[0].id,actPayAmt:aa[0].actPayAmt*100,actPayTm:aa[0].actPayTm },
                    url: '<%=path%>/finpayschfee/finance/addTuiPay.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.code == 1) {
                            top.$.ligerDialog.SQalert({content: "保存成功", SQ_type: "success"});
                            
                        } else {
                            top.$.ligerDialog.SQalert({content: msg.info, SQ_showButtons : true,SQ_type: "error"});
                        }
                    }
                });
        	}

        }
        if (editFlag) {
            saveInfo();//保存（修改）还款信息
        }
    }

    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value && "" != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //根据 支付明细id获取历史还款
    function getrepayHisRow(paySchDtlId, repayDtlId){
        //回调刷新列表
        /*var callback = function () {
            grid.reload();
        };*/
        if(!repayDtlId){
            return;
        }//ID为空不执行
        Add_navTab('repay_his_flow'+repayDtlId,'还款申请记录','<%=path%>/finance/finRepayApplyInfo/toRepayHisPage.do?paySchDtlId='+paySchDtlId+'&&repayDtlId='+repayDtlId);
    }

</script>
</body>
</html>